<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box {
        width: 500px;
        background-color: aqua;
        padding: 10px;
      }
      .box1 {
        width: 100%;
        height: 50px;
        text-align: center;
        line-height: 50px;
        font-size: 25px;
        color: white;
      }
      .box2 {
        width: 400px;
        height: 100px;
        background-color: white;
        padding: 5px;
        margin-bottom: 20px;
        border-radius: 10px;
        margin-left: 50px;
      }
      .box2 > input {
        width: 150px;
        border-radius: 10px;
        outline: none;
        border: 1px solid skyblue;
        margin-bottom: 10px;
      }
      .box2 > button {
        width: 60px;
        outline: none;
        border: 0;
        border-radius: 10px;
        height: 20px;
        background-color: cyan;
      }
      .table {
        width: 400px;

        padding: 5px;
        margin-bottom: 20px;
        border-radius: 10px;
        margin-left: 50px;
      }
      .thead,
      .tbody {
        display: flex;
        justify-content: space-between;
        text-align: center;
        border: 1px solid skyblue;
        margin-bottom: 3px;
      }
    </style>
  </head>
  <body>
    <div id="box">
      <div class="box1">学生系统</div>
      <div class="box2">
        姓名<input type="text" v-model="Studentname" /> 
        年龄<input type="text"v-model="Studentage"/>
        性别<input type="text" v-model="Studentsex" />
        <button @click="add">添加</button>
        <button class="rank"  @click="rank">排序</button>
      </div>
      <div class="table">
        <div class="thead">
          <div class="th">姓名</div>
          <div class="th">年龄</div>
          <div class="th">性别</div>
          <div class="th">操作</div>
        </div>
        <div v-for="(item,key) in user"  class="tbody">
          <div class="td">{{item.name}}</div>
          <div class="td">{{item.age}}</div>
          <div class="td">{{item.gender}}</div>
          <div class="td" @click="del(key)">删除</div>
        </div>
          <!-- <div class="td">2</div>
          <div class="td">3</div> -->
          <!-- <div class="del">删除</div> -->
        </div>
      </div>
    </div>
  </body>
  <script src="./static/vue.js"></script>
  <script>
    new Vue({
      el: "#box",
      data: {
        Studentname: "",
        Studentage: "",
        Studentsex: "",
        user:[{name:"张三",age:20,gender:"男",num:1}],
        num : 1,
      },
      methods:{
          add(){
            this.num++
            this.user.push({name:this.Studentname,age:this.Studentage,gender:this.Studentsex,num:this.num})
          },
          del(key){
            this.user.splice(key,1)

          },
          rank(){
            this.user.sort((a,b)=>a.age-b.age);
          }
      }
    });
  </script>
</html>
